home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1988 / 05 / spmtpl.c < prev    next >
Text File  |  1988-08-18  |  3KB  |  104 lines

  1. Written by Bill Hall, Olivetti ATC.
  2.  
  3. #define INCL_PM
  4. #include <os2.h>
  5. #include <stddef.h>
  6. #include <string.h>
  7.  
  8. #define EXTERN            /* all globals are declared in this module */
  9. #include "spmtpl.h"
  10.  
  11. /* local function declarations */
  12. void MainWndPaint(HWND hWnd, HPS hPS);
  13. BOOL WindowIsIconic(HWND hWnd);
  14.  
  15. /* entry point for program */
  16. int cdecl main(int argc, char *argv[])
  17. {
  18.  
  19.     QMSG qmsg;
  20.  
  21.   /* call initialization */
  22.     if (!InitProgram(argc, argv))
  23.     return FALSE;
  24.  
  25.   /* fall into message loop */
  26.     while (WinGetMsg(hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0))
  27.         WinDispatchMsg( hAB, (PQMSG)&qmsg );
  28.  
  29.   /* program exit */
  30.     WinDestroyWindow(hwndFrame);
  31.     WinDestroyMsgQueue(hmqMsgQ);
  32.     WinTerminate(hAB);
  33. }
  34.  
  35. /* main window message loop */
  36. MRESULT FAR PASCAL MainWndProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  37. {
  38.  
  39.     HPS hPS;        /* handle to PM display context */
  40.  
  41.     switch (msg) {
  42.  
  43.     case WM_CREATE:        /* called when main window is created */
  44.         WndCreate(hWnd);
  45.         break;
  46.  
  47.     case WM_CLOSE:        /* called when main window is closed */
  48.             WinPostMsg(hWnd, WM_QUIT, 0L, 0L) ;
  49.             break;
  50.  
  51.        case WM_PAINT:        /* called when window needs repainting */
  52.         hPS = WinBeginPaint(hWnd, (HPS)NULL, (PRECTL)NULL);
  53.         MainWndPaint(hWnd, hPS);
  54.         WinEndPaint( hPS );
  55.             break;
  56.  
  57.         case WM_ERASEBACKGROUND:    /* have PM take care of background */
  58.             return(TRUE);
  59.             break;
  60.  
  61.         default:        /* all other messages go here */
  62.             return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  63.             break;
  64.     }
  65.     return(0L);
  66. }
  67.  
  68. void MainWndPaint(HWND hWnd, HPS hPS)
  69. {
  70.  
  71.   /* print a string in the icon area */
  72.     if (WindowIsIconic(hWnd)) {
  73.         POINTL pt;
  74.     pt.x = 0;
  75.       pt.y = 0;
  76.     GpiMove(hPS, (PPOINTL)&pt);
  77.     pt.x = xIconsize-1;
  78.     pt.y = yIconsize-1;
  79.         GpiBox(hPS, 2L, (PPOINTL)&pt, 0L, 0L);
  80.         pt.x = 0;
  81.         pt.y = 2 * (yIconsize - CharHeight) / 3;
  82.         GpiCharStringAt( hPS, (PPOINTL)&pt, (LONG)strlen(szIcon), (PCH)szIcon);
  83.     }
  84. }
  85.  
  86. /* 
  87.    Return TRUE if main window is iconic.
  88.    This kludge is needed since WinQueryWindowPos is not yet fully implemented.
  89. */
  90. BOOL WindowIsIconic(HWND hWnd)
  91. {
  92.  
  93.     RECTL cRect;
  94.  
  95.   /* get the current window client rectangle */
  96.     WinQueryWindowRect(hWnd, (PRECTL)&cRect);
  97.  
  98.   /* compare with size when window is iconic */
  99.     if ((cRect.xRight == xIconsize) && (cRect.yTop == yIconsize))
  100.     return TRUE;
  101.  
  102.     return FALSE;
  103. }
  104.